<?php
/**
 * Created by PhpStorm.
 * User: divya
 * Date: 2018/7/30
 * Time: 下午4:16
 */

namespace app\api\controller\v1;


use app\api\validate\Count;
use app\api\validate\IDMustBePositiveInt;
use app\lib\exception\ProductException;
use think\Controller;
use app\api\model\Product as ProductModel;
class Product extends Controller
{
    /**
     *
     * */
    public static function recent($count=15){
        (new Count())->goCheck();
        $reusults = ProductModel::getRecent($count);
        if ($reusults->isEmpty()){
            throw new ProductException();
        }
        //临时隐藏  在detaBase里将返回对象设置成collection
        $reusults->hidden(['summary']);
        return $reusults;
    }
    public function getAllInCategory($id){

    }
    public function getDetailByID($id){
        (new IDMustBePositiveInt())->goCheck();
        $detail = ProductModel::getDetail($id);
        if (!$detail){
            throw new ProductException();
        }
        $detail->hidden(['summary']);
        return $detail;
    }
}